if(typeof Ext.user.method.groupidstore == 'undefined') Ext.user.method.groupidstore = Ext.user.method.groupid();
Ext.user.nodelist = Ext.extend(Ext.grid.EditorGridPanel, {
    title: '节点面板',
    store: 'nodeliststore',
	style:'margin:0 auto;',
    width: 700,
    height: 500,
	columnLines:true,
	loadMask: true,
	frame:true,
	trackMouseOver:true,
	buttonAlign: 'left',
	viewConfig: {forceFit: true},
	id:'nodelist',
	renderTo:'node_index',
	tbar:[],
	sm: new Ext.grid.RowSelectionModel({ 
			singleSelect: true//如果不想强制每次只能选一行，可以把这句代码注释掉 
	}),
	listeners:{
		celldblclick:function(g, r,c, e){
			var id = g.getSelectionModel().getSelected().id;
			if(c == 0){
				//Ext.getCmp('nodelist').getStore().clear();
				Ext.getCmp('nodelist').getStore().load({
					params:{do:'menu',p:id},
					callback:function(r,o,s){		
				},
				});
			}
		},
		validateedit:function(e){
			//alert(e.grid.store.getCount());
		}
	},
	button:function(){
	 var button = new Ext.Button({text:'添加节点',renderTo:'node_button',
		 handler:function(){
			var windows = new Ext.user.nodeWindow();
			windows.show();
			
		}
	 });
	 var button = new Ext.Button({text:'刷新',renderTo:'node_button',
		 handler:function(){
			Ext.StoreMgr.lookup('nodeliststore').reload();
		}
	 });
	},
    initComponent: function() {
        this.columns = [
            {
                xtype: 'gridcolumn',
                header: '编号',
                dataIndex: 'id',
                sortable: true,
                width: 100,
				editable: false,
            },
            {
                xtype: 'gridcolumn',
                header: '模块名',
                dataIndex: 'name',
                sortable: true,
                width: 100,
                editor: {
                    xtype: 'textfield',
                    name: 'name'
                }
            },
            {
                xtype: 'gridcolumn',
                header: '名称',
                dataIndex: 'title',
                sortable: true,
                width: 100,
                editor: {
                    xtype: 'textfield',
                    name: 'title'
                }
            },
            {
                xtype: 'gridcolumn',
                header: '组',
                dataIndex: 'group_id',
                sortable: true,
                width: 100,
				renderer:Ext.user.method.group,
                editor: {
                    xtype: 'combo',
					name: 'group_id',
					store:Ext.user.method.groupidstore,
					displayField:'title',
					valueField:'id',
					editable:false,
					typeAhead: true,
					forceSelection: true,
					mode: 'local',
					triggerAction: 'all',
					selectOnFocus:true,
                },
				
            },
            {
                xtype: 'gridcolumn',
                header: '状态',
                dataIndex: 'status',
                sortable: true,
                width: 100,
				renderer:Ext.user.method.nodestatus,
                editor: {
                    xtype: 'combo',
                    name: 'status',
					store:Ext.user.method.statusid(),
					displayField:'text',
					valueField:'value',
					editable:false,
					typeAhead: true,
					forceSelection: true,
					mode: 'local',
					triggerAction: 'all',
					selectOnFocus:true,
                }
            },
            {
                xtype: 'gridcolumn',
                header: '操作',
                dataIndex: 'id',
                sortable: true,
                width: 100,
				renderer:function(n){return '<a href="javascript:Ext.user.deletenodeeditgrid('+n+');">删除</a>'},
            }
        ];
        Ext.user.nodelist.superclass.initComponent.call(this);
    }
});
Ext.user.nodeliststoreWriter = new Ext.data.JsonWriter({
    encode: false
}); 

Ext.user.proxy = new Ext.data.HttpProxy({
    api: {
			read : Ext.user.baseUrl +'/Node/data/',
			update: Ext.user.baseUrl +'/Node/edit/',
			destroy: Ext.user.baseUrl +'/Node/delete/'
		 }
});
Ext.user.nodeliststore = Ext.extend(Ext.data.JsonStore, {
    listeners:{
		update:function(s,r,o){
			s.commitChanges();
		}
	},
	constructor: function(cfg) {
        cfg = cfg || {};
        Ext.user.nodeliststore.superclass.constructor.call(this, Ext.apply({
            storeId: 'nodeliststore',
			proxy: Ext.user.proxy,
            autoLoad: true,
			writer: Ext.user.nodeliststoreWriter,
			root:'list',
			baseParams: {
                do: 'menu'
            },
			fields: ['id','name','title','group_id','status'],
        }, cfg));
    }
});
Ext.user.nodeWindow = Ext.extend(Ext.Window, {
    title: '节点窗口',
	id:'nodeWindow',
    width: 750,
    height: 310,
    border: false,
	modal:true,
	listeners:{
		close:function(a){
				Ext.user.centermenu.setDisabled(false);
			  }
	},
	buttons:[
		{text:'添加节点',handler:function(){
			Ext.user.method.submitForm('nodeform','/Node/add/',{s:function(){
				Ext.getCmp('nodeWindow').close();
			},
			f:function(){
				alert('添加失败');
			}
			
			},'POST');
		}},{text:'重置',handler:function(){
			Ext.getCmp('nodeform').form.reset();
		}}
	],
    initComponent: function() {
        this.items = [
            {
				id:'nodeWindowpanel',
                xtype: 'panel',
                title: '当前父节点',
                border: false
            },
            {
                xtype: 'panel',
                title: '',
                layout: 'column',
                border: false,
                items: [
                    {
                        xtype: 'panel',
                        title: '',
                        columnWidth: 0.4,
                        border: false,
                        items: [
                            {
                                xtype: 'treepanel',
                                title: '',
                                height: 220,
                                autoScroll: true,
								listeners:{
									click:function(n,e){
										var parnel = Ext.getCmp('nodeWindowpanel');
										if(n.attributes.id != 'menu'){
											var form = Ext.getCmp('nodeform');
											form.getForm().setValues({pid:n.attributes.id});
										}
										parnel.setTitle('当前节点：'+n.attributes.text);
									}
								},
                                root: {
                                    text: '菜单',
                                    id: 'menu'
                                },
                                loader: {
                                    url: Ext.user.baseUrl + '/Node/data/',
                                    nodeParameter: 'p',
                                    baseParams: {
                                        do: 'menu',
                                        tree: 'tree'
                                    },
                                    requestMethod: 'POST',
                                    baseAttrs: ''
                                }
                            }
                        ]
                    },
                    {
                        xtype: 'form',
                        title: '',
                        columnWidth: 0.6,
						id:'nodeform',
                        border: false,
                        items: [
                            {
                                xtype: 'fieldset',
                                title: '新增节点',
                                style: 'margin-left:20px;margin-right:20px;',
                                height: 221,
                                items: [
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '应用名',
                                        anchor: '100%',
                                        name: 'name',
										blankText:'不能为空',
										allowBlank:false,
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '显示名',
                                        anchor: '100%',
                                        name: 'title',
										blankText:'不能为空',
										allowBlank:false,
                                    },
                                    {
										xtype: 'combo',
										name: 'group_id',
										store:Ext.user.method.groupidstore,
										displayField:'title',
										valueField:'id',
										editable:false,
										typeAhead: true,
										forceSelection: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
										fieldLabel: '分组',
										anchor: '100%',
										hiddenName:'group_id',
										hiddenValue:'id',
										emptyText:'请选择',
										blankText:'不能为空',
										allowBlank:false,
                                    },
                                    {
										xtype: 'combo',
										name: 'status',
										store:Ext.user.method.statusid(),
										displayField:'text',
										valueField:'value',
										editable:false,
										typeAhead: true,
										forceSelection: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        fieldLabel: '状态',
                                        anchor: '100%',
										hiddenName:'status',
										hiddenValue:'value',
										emptyText:'请选择',	
										blankText:'不能为空',
										allowBlank:false,
                                    },
                                    {
                                        xtype: 'textarea',
                                        anchor: '100%',
                                        fieldLabel: '描述',
                                        name: 'intro'
                                    },
									{
                                        xtype: 'hidden',
                                        anchor: '100%',
                                        name: 'pid',
                                        value: 1
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ];
        Ext.user.nodeWindow.superclass.initComponent.call(this);
    }
});



